package com.cee.admin.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cee.admin.common.BaseController;
import com.cee.common.core.query.BasePageQuery;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.sys.query.SysLogQuery;
import com.cee.domain.modules.sys.vo.SysUserOperationLogVo;
import com.cee.ds.common.constants.PermissionConstants;
import com.cee.ds.modules.sys.service.ISysUserOperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author wsz
 * @since 2024/2/6
 */
@RestController
@RequestMapping("/api/sys/user/operationLog")
@Tag(name = "系统用户-操作日志")
public class SysUserOperationLogController extends BaseController {

    @Autowired
    private ISysUserOperationLogService operationLogService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @RequiresPermissions(PermissionConstants.SYS_BACKEND_LOG_PREFIX + PermissionConstants.READ)
    public Result<Page<SysUserOperationLogVo>> queryPage(SysLogQuery query, BasePageQuery<SysUserOperationLogVo> pageQuery) {
        return success(operationLogService.queryPageVo(pageQuery.generatePage(), query));
    }

    @GetMapping("/export")
    @Operation(summary = "导出")
    @RequiresPermissions(PermissionConstants.SYS_BACKEND_LOG_PREFIX + PermissionConstants.EXPORT)
    public void export(SysLogQuery query) throws IOException {
        operationLogService.export(query, wrapDownloadResponse("操作日志.xlsx"));
    }
}
